import { createRouter, createWebHistory } from 'vue-router'

const routes =[
  {
    path: '/',
    name: 'Layout',
    component: ()=> import('../components/layout/index.vue'), // 默认加载的组件
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: ()=> import('../views/home/index.vue'),
      },
      {
        path: 'login',
        name: 'login',
        component: ()=> import('../views/login/index.vue'),
        meta: { title: '登录', customBanner: true },
      },
      {
        path:'timeline',
        name: 'Timeline',
        component: ()=> import('../views/timeline/index.vue'),
        meta: { title: '时间轴' }

      },
      {
        path: 'more/about',
        name: 'About',
        component: () => import('../views/more/about/index.vue'),
        meta: { title: '关于' }
      },
      {
        path: 'article/:id',
        name: 'Article',
        component: () => import('../views/article/index.vue'),
        meta: { customBanner: true }
      },
      {
        path: 'test',
        name: '测试',
        component: () => import('../views/test.vue'),
        meta: { customBanner: true }
      },
      {
        path: 'talk',
        name: '说说',
        component: () => import('../views/talk/index.vue'),
        meta: { customBanner: true, title: '说说' }
      },
      {
        path: 'album',
        name: '相册',
        component: () => import('../views/album/index.vue'),
        meta: { title: '相册', customBanner: true }
      },
      {
        path: 'photos/:id',
        name: '照片',
        component: () => import('../views/album/photo/index.vue'),
        meta: { title: '照片', customBanner: true }
      },
      {
        path: 'tools',
        name: '工具',
        component: () => import('../views/tools/index.vue'),
        meta: { title: '网站导航' }
      },
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior(_, __, savedPosition) {
    // 通过浏览器前进/后退按钮触发时，恢复之前的滚动位置
    if (savedPosition) {
      return savedPosition
    } else {
      // 否则滚动到顶部
      return { left: 0, top: 0 }
    }
  }
})

export default router